package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.ProgramSyncStatusDao;
import com.bestv.search.common.model.ProgramSyncStatus;

import java.util.List;

public class ProgramSyncStatusDaoHibernate extends GenericDaoHibernate<ProgramSyncStatus, Long> implements
        ProgramSyncStatusDao {

    public ProgramSyncStatusDaoHibernate() {
        super(ProgramSyncStatus.class);
    }

    @Override
    public ProgramSyncStatus get(String siteCode, String sysName, int serverNo, String fieldName) {
        String hql = "from ProgramSyncStatus where siteCode=? and sysName=? and serverNo=? and fieldName=?";
        Object[] args = {siteCode, sysName, serverNo, fieldName};

        // siteCode, sysName, serverNo, fieldName are logic primary key of
        // ProgramSyncTime table, so should return null or one ProgramSyncTime.
        List<?> list = getHibernateTemplate().find(hql, args);
        return list == null || list.size() == 0 ? null : (ProgramSyncStatus) list.get(0);
    }
}